﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="qrc:/resource/qwebchannel.js"></script>
    <title>Document</title>
    <style>
        img{
            width:400px;
            height:300px;
        }
    </style>
</head>

<body>
    <input type="button" value="调用Qt函数" id="btn" onclick="btnAction()" />
    <div>
        <img src="qrc:/resource/1.png"/>
    </div>   
</body>
<script type="text/javascript">
    
     window.onload = function () {
        clannel = new QWebChannel(qt.webChannelTransport, function (channel) {
            window.HostApplication = channel.objects.HostApplication
        })
    }
    function add(a, b) {
        alert("js接收到Qt消息")
        console.log('input', a, b)
        return parseInt(a) + parseInt(b)
    }

    function btnAction() {
        HostApplication.recieveJsMessage("Hello Qt!")
    }
</script>

</html>